//axios 二次封装
import axios from "axios"
import nprogress from "nprogress"
import "nprogress/nprogress.css"
import store from "@/store"


const requests = axios.create({
    baseURL:'/api',
    timeout: 8000,
})

// 请求拦截
requests.interceptors.request.use( (config)=> {
    //携带uuid
    if(store.state.shopcart.uuid_token){
        config.headers.userTempId =store.state.shopcart.uuid_token
    }
    //携带token
    if(store.state.login.token){
        config.headers.token=store.state.login.token
    }
    nprogress.start()
    return config
    
});

// 响应拦截
requests.interceptors.response.use((response)=>{
    nprogress.done()
    return response.data;
   
},  (error)=>{
    return Promise.reject(error)
});

export default requests
